<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Log;

class LogFormatter extends \GuzzleHttp\MessageFormatter
{
    public $template;
    private static $logStartTime = 0;
    private static $ts;
    public function __construct($template)
    {
        parent::__construct($template);
        self::$logStartTime = microtime(true);
        $this->template = $template;
        $timezone = new \DateTimeZone(date_default_timezone_get() ?: "UTC");
        if(PHP_VERSION_ID < 70100) {
            self::$ts = \DateTime::createFromFormat("U.u", sprintf("%.6F", microtime(true)), $timezone);
        } else {
            self::$ts = new \DateTime(NULL, $timezone);
        }
    }
    public function format(\Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response = NULL, \Exception $error = NULL)
    {
        $this->template = str_replace("{pid}", getmypid(), $this->template);
        $this->template = str_replace("{cost}", self::getCost(), $this->template);
        $this->template = str_replace("{start_time}", self::$ts->format("Y-m-d H:i:s.u"), $this->template);
        return (new \GuzzleHttp\MessageFormatter($this->template))->format($request, $response, $error);
    }
    private static function getCost()
    {
        return microtime(true) - self::$logStartTime;
    }
}

?>